﻿using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Runnergame.Model
{
    class Player
    {
        private const float PLAYER_STARTSPEED = 0.1f;
        public float playerSpeed;
        public float playerSize = 1f;
        public Vector2 playerPosition;
        public Vector2 velocity;
        public Vector2 gravity = new Vector2(0, +20f);
        float time;
        bool isJumping = false;

        public Player()
        {
            playerSpeed = PLAYER_STARTSPEED;
            playerPosition = new Vector2(5, 7);

        }
        internal void Update(GameTime gameTime) 
        {
            time = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (isJumping)
            {
                velocity += gravity * time;
                playerPosition += velocity * time; 
            }
            Collision();

            System.Diagnostics.Debug.WriteLine(playerPosition.Y);

        }

        internal void jump()
        {
            //velocity.X = velocity.X + 0.5f;
            velocity.Y = velocity.Y - 10f;

            isJumping = true;

        }
        internal void Collision()
        {

            if (playerPosition.Y > 7)
            {
                playerPosition.Y = 7;
                isJumping = false;
            }
            if (playerPosition.Y < 0)
            {
                playerPosition.Y = playerPosition.Y * -1;
            }
            if (playerPosition.X > 10)
            {
                playerPosition.X = 0;
                playerSpeed += 0.05f;
            }
            if (playerPosition.X < 0)
            {
                playerPosition.X = 10;
                playerSpeed += 0.05f;
            }
        
        }
    }
}
